package com.example.smartcity.ui.newS

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations
import androidx.lifecycle.ViewModel
import com.example.smartcity.logic.Repository
import com.example.smartcity.logic.model.NewSEntity
import com.example.smartcity.logic.model.NewSTitleEntity
import com.example.smartcity.logic.model.Slideshow

class NewsViewModel : ViewModel() {

    /**
     * 轮播图
     */
    private val slideshowData = MutableLiveData<Map<String, Int>>()
    val slideshowList = ArrayList<Slideshow.Rows>()
    val slideshowLiveData = Transformations.switchMap(slideshowData){ query ->
        Repository.getSlideshow(query)
    }
    fun slideshow(map: Map<String, Int>){
        slideshowData.value = map
    }


    /**
     * 新闻
     */
    private val newSData = MutableLiveData<Int>()
    val newSList = ArrayList<NewSEntity.Rows>()
    val newSLiveData = Transformations.switchMap(newSData){query ->
        Repository.getNewSEntityType(query)
    }
    fun newS(test: Int){
        newSData.value = test
    }


    /**
     * 新闻专栏
     */
    private val newSTitleData = MutableLiveData<String>()
    val newSTitleList = ArrayList<NewSTitleEntity.Rows>()
    val newSTitleLiveData = Transformations.switchMap(newSTitleData){
        Repository.getNewSTitle()
    }
    fun newSTitle(test: String){
        newSTitleData.value = test
    }
}